package com.gtw.modules.sys.controller;

import com.gtw.common.utils.PageUtils;
import com.gtw.common.utils.Query;
import com.gtw.common.utils.R;
import com.gtw.modules.entity.TbFees;
import com.gtw.modules.sys.service.SysFeesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by wuye on 2018/4/20.
 */
@RestController
@RequestMapping("/sys/fees")
public class SysTbFeesController extends AbstractController{

    @Autowired
    private SysFeesService feesService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:fees:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<TbFees> feesList = feesService.queryList(query);
        int total = feesService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(feesList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:fees:info")
    public R info(@PathVariable("id") Integer id){
        TbFees fees = feesService.queryObject(id);

        return R.ok().put("fees", fees);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:fees:save")
    public R save(@RequestBody TbFees fees){
        fees.setCreatetime(new Date());
        fees.setCreateuser(getUser().getUsername());
        feesService.save(fees);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:fees:update")
    public R update(@RequestBody TbFees fees){
        feesService.update(fees);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("SYS:fees:delete")
    public R delete(@RequestBody Integer[] ids){
        feesService.deleteBatch(ids);

        return R.ok();
    }
}
